<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Shop\Customer;
use GatewayClient\Gateway;

class EchartController extends Controller
{
    //男女人数统计
    public function sex_total()
    {
        $data = [
            ['value' => Customer::where('sex', 0)->count(), 'name' => '女'],
            ['value' => Customer::where('sex', 1)->count(), 'name' => '男']
        ];
        return $data;
    }

    //省份人数统计
    public function province_total()
    {
        $customer_total = \DB::table('customers')->
        select(\DB::raw('province as name, count(*) as value'))->groupBy('province')->get();
        return $customer_total;
    }

    public function bind(Request $request)
    {
        Gateway::$registerAddress = '127.0.0.1:1238';
        Gateway::joinGroup($request->client_id, 'sex');
    }
}
